package operation;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2023-08-17
 * Time: 10:50
 */
public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要借阅图书的名字");
        String name=sc.nextLine();
        
        //遍历书架，去查找有无此书
        int currentSize=bookList.getUsedSized();
        for (int i = 0; i <currentSize; i++) {
            if(name.equals(bookList.getBooks(i).getName())){
                //如果有，看它是否有被借出
                if(bookList.getBooks(i).isBorrowed()==false){
                    System.out.println("借阅成功");
                    bookList.getBooks(i).setBorrowed(true);
                    return;
                }else{
                    System.out.println("该书已被借出");
                    return;
                }
            }
        }
        System.out.println("没有此书");
    }
}
